package com.zcp.demo;


import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2017/4/1.
 */

public class HttpMethods {
    public Retrofit retrofit;
    private TuijianService tuijianService;

    private static final int DEFAULT_TIMEOUT = 5;

    //私有构造方法
    private HttpMethods() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
//        retrofit=new Retrofit.Builder()
//                .client(builder.build())
//                .baseUrl(url)
//                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                .addConverterFactory(GsonConverterFactory.create())
//                .build();
        tuijianService = RetrofitManager.getInstance().create(TuijianService.class);
        //this.tuijianService =retrofit.create(TuijianService.class);
    }

    //在访问HttpMethods时创建单例
    private static class SingletonHolder {
        private static final HttpMethods INSTANCE = new HttpMethods();
    }

    //获取单例
    public static HttpMethods getInstance() {
        return SingletonHolder.INSTANCE;
    }


    public void getData(Subscriber<TuijianInfo> subscriber, String platform, String device, String build) {
        tuijianService.getInfo(platform, device, build)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

}
